package com.a16.yuejian.yuejian.fragment;

import android.content.Context;
import android.content.SharedPreferences;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.a16.yuejian.yuejian.R;
import com.a16.yuejian.yuejian.adapter.CoachAdapter;
import com.a16.yuejian.yuejian.javabean.Club;
import com.a16.yuejian.yuejian.javabean.Master;
import com.a16.yuejian.yuejian.listener.ClubListener;
import com.a16.yuejian.yuejian.listener.Listener;
import com.a16.yuejian.yuejian.model.ClubModel;

import java.util.List;

public class ClubIntroFragment extends Fragment {
    private TextView jianjie,dizhi,dianhua,shijian;
    private View view=null;
    private SharedPreferences sp;
    private RecyclerView recyclerView;

    Listener<Master> listener = new Listener<Master>() {
        @Override
        public void onResponse(List<Master> t) {
           recyclerView.setAdapter(new CoachAdapter(getActivity(),t));
        }

        @Override
        public void onFail() {

        }
    };

    ClubListener clubListener = new ClubListener() {
        @Override
        public void onResponse(Club info) {
            jianjie.setText(info.getClubintroduction());
            dizhi.setText(info.getAddress());
            dianhua.setText(info.getClubphone());
            shijian.setText(info.getWorktime());
        }

        @Override
        public void onFail() {

        }
    };

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState)
    {
        view=inflater.inflate(R.layout.clubintro_fragment, container, false);
        initViews();
        ClubModel clubModel = new ClubModel();
        clubModel.getclub(sp.getString("clubid",""),clubListener);
        clubModel.getclubcoach(sp.getString("clubid",""),listener);
        return view;
    }

    private void initViews() {
        jianjie = (TextView)view.findViewById(R.id.club_jianjie);
        dizhi = (TextView)view.findViewById(R.id.club_dizhi);
        dianhua = (TextView)view.findViewById(R.id.club_dianhua);
        shijian = (TextView)view.findViewById(R.id.club_shizhong);
        sp = getActivity().getSharedPreferences("userinfo", Context.MODE_PRIVATE);
        recyclerView = (RecyclerView)view.findViewById(R.id.rv_coach);
        recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity()));
    }
}
